#include <gtest/gtest.h>
#include "../stdlib/itoa.h"
#include "../stdlib/strtol.h"

TEST(IANDSTR, ITOA) {
  ASSERT_STREQ("12", zitoa(12, NULL, 10));
  ASSERT_STREQ("-12", zitoa(-12, NULL, 10));
  ASSERT_STREQ("f", zitoa(15, NULL, 16));
  ASSERT_STREQ("e", zitoa(14, NULL, 16));
  ASSERT_STREQ("d", zitoa(13, NULL, 16));
  ASSERT_STREQ("c", zitoa(12, NULL, 16));
  ASSERT_STREQ("b", zitoa(11, NULL, 16));
  ASSERT_STREQ("a", zitoa(10, NULL, 16));
  ASSERT_STREQ("11", zitoa(17, NULL, 16));
}

TEST(IANDSTR, ZSTRTOL) {
  // decimal
  ASSERT_EQ(2, zstrtol_l("2", 10));
  ASSERT_EQ(0, zstrtol_l("0", 10));
  ASSERT_EQ(-1, zstrtol_l("-1", 10));
  ASSERT_EQ(11, zstrtol_l("11", 10));
  ASSERT_EQ(-11, zstrtol_l("-11", 10));

  // oct
  ASSERT_EQ(2, zstrtol_l("02", 0));
  ASSERT_EQ(18, zstrtol_l("022", 0));

  // hex
  ASSERT_EQ(2, zstrtol_l("0x2", 0));
  ASSERT_EQ(18, zstrtol_l("0x12", 0));
  ASSERT_EQ(34, zstrtol_l("0x22", 16));
  ASSERT_EQ(-36, zstrtol_l("-0X24", 16));
  ASSERT_EQ(42, zstrtol_l("0X2a", 16));
  ASSERT_EQ(162, zstrtol_l("0Xa2", 16));
}
